<?php

namespace app\common\model\Active;

use think\Model;

class Active extends Model
{
    protected $name = 'business_active';

    //开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    //定义时间戳字段名
    protected $createTime = 'createtime';

    //关闭自动更新时间戳
    protected $updateTime = false;

    //开启过滤
    protected $field = true;

    protected $append = [
        'createtime_text', //创建时间
        'starttime_text', //开始时间
        'endtime_text', //结束时间
    ];

    //创建时间
    public function getCreatetimeTextAttr($value, $data)
    {
        $createtime = isset($data['createtime']) ? $data['createtime'] : '';
        if ($createtime) {
            return date('Y-m-d H:i', $createtime);
        } else {
            return '';
        }
    }

    //开始时间
    public function getStarttimeTextAttr($value, $data)
    {
        $starttime = isset($data['starttime']) ? $data['starttime'] : '';
        if ($starttime) {
            return date('Y-m-d H:i', $starttime);
        } else {
            return '';
        }
    }

    //结束时间
    public function getEndtimeTextAttr($value, $data)
    {
        $endtime = isset($data['endtime']) ? $data['endtime'] : '';
        if ($endtime) {
            return date('Y-m-d H:i', $endtime);
        } else {
            return '';
        }
    }
}
